new Vue({
    el: '#app',
    data(){
        return{
            username:'',qqnum:'',email:'',password:'',conpassword:'',ver:'',
            off:false,on:true,verimg:'',srcver:'',w:'../',
            message:''
        }
    },
    methods: {
        logon:function() {
            window.open("../login.php");
            window.opener=null;window.close();
        },
        login_open:function(){
            var numRe = new RegExp('^[-\\+]?([0-9]+\\.?)?[0-9]+$');
            var reg=/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
            if(!this.username){
                this.$message.error('请输入用户名！');
            }else if(!this.qqnum){
                this.$message.error('请输入QQ账号！（头像与登录凭证）');
            }else if(!this.email){
                this.$message.error('请输入Email！(用于找回密码)');
            }else if(!this.ver){
                this.$message.error('请输入验证码！');
            }else if(!this.password){
                this.$message.error('请输入密码！');
            }else if(!this.conpassword){
                this.$message.error('请输入确认密码！');
            }else if(this.password != this.conpassword){
                this.$message.error('你输入的密码和确认密码不一致！');
            }else if(this.username.length <2 || this.username.length >10){
                this.$message.error('你输入的用户名不合法！（2~10位）');
            }else if(!reg.test(this.email)){
                this.$message.error('你输入的邮箱地址不合法！(用于密码找回)');
            }else if(this.ver.length != 5){
                this.$message.error('请正确输入获取的验证码！(注册凭证)');
            }else if(!numRe.test(this.qqnum) || this.qqnum.length <6 || this.qqnum.length >10){
                this.$message.error('你输入的QQ账号不合法！（6~10位，非法QQ账号直接封禁！）');
                this.$notify({
                  title: '⚠警告',
                  message: '请认真注册账号信息，登录操作比注册更快捷！授权你的QQ是为了获取头像，邮箱为你找回密码方便，密码是通过MD5加密存储在数据库！包括管理员在内都破解不了的！',
                  duration: 0
                });
            }else if(this.password.length <6 ){
                this.$message.error('你输入的密码不符号规定！（6~15位）');
            }else{
                
                var that = this;
                axios.post("../api/logon.php",{
                    fun:"login",  username:this.username,
                    qqnum:this.qqnum,  email:this.email,
                    ver:this.ver,   srcver:this.srcver,
                    password:this.password,  conpassword:this.conpassword
                }).then(function(resp) {
                    var data = resp.data;
                    if(data.stat == '200'){
                        that.$message({ message: data.msg , type: 'success' });
                        window.location.href=that.w;
                        that.password = '';  that.conpassword = '';
                        that.username = '';  that.email = '';
                        that.qqnum = '';
                        
                    }else if(data.stat == '400'){ 
                        that.$message.error(data.msg);  
                    }else{
                        alert("注册时服务器发生错误！\n\n错误代码:"+data);
                    }
                    that.ver = '';  that.ver_img();
                });
            }
        },
        ver_img:function(){
            var srcimg = Math.round(Math.random()*20);
            this.srcver = md5(srcimg);
            this.verimg = '../style/image/ver/'+this.srcver+'.png';
        },
        logincookie:function(){
            var that = this;
                axios.post("../api/logon.php",{
                    fun:"logonstate"
                }).then(function(resp) {
                    var data = resp.data;
                    if(data.stat == '200'){
                        that.$message({ message: data.username+'，'+data.msg , type: 'success' });
                        window.location.href=that.w;
                        that.username = '';
                    }
                });
        }
        
    },
    mounted:function(){
        this.logincookie();
        this.ver_img();
    },created(){
		this.ver_img();
    }
})